/**
 * yeganaaa@163.com
 * author: (مۇختەرجان مەخمۇت) muhtaer mahmood
 * 6/5/2020, 6:16 PM GMT+06:00
 */
import {AmqpConnectionBridgeHost, AmqpConnectionBridgeServer, AmqpSchema} from "./AmqpConnectionBridgeHost";

async function main() {
    const server = new AmqpConnectionBridgeServer({
        userName: "guest",
        password: "guest",
        port: 5672,
        host: "47.97.254.188",
    }, {virtualEndPoint: "TestServer"})
    server.onClientConnected = client => {
        console.log("a new Client connected")
    }
    server.onLaunch = () => {
        console.log("Server launch successfully!")
    }
    await server.prepareForLaunch()
    const testHost = new AmqpConnectionBridgeHost({
        userName: "guest",
        password: "guest",
        port: 5672,
        host: "47.97.254.188",
    }, {virtualEndPoint: "TestServer"})
    testHost.onConnected = () => {
        console.log("Client connected")
    }
    testHost.onClosed = () => {}
    testHost.onMessageReceived = message => {
        console.log(`<---: ${message}`)
    }
    await testHost.initialize()
    console.log("OK")
    console.log("Preparing for sen message...")
    let index = 0;
    setInterval(() => {
        testHost.send(Buffer.from(`Hello world from client, indx is: ${index++}, time: ${Date.now()}`), error => {})
    }, 3000)

    console.assert(10 + 20 == 31)
}

main()

